#include "ReadMap.h"
string CReadMap::readFile(char *str)
{
	FILE *ffile; 
	char ch; 
	string st=""; 
	ffile=fopen(str,"rb"); 
	if(!ffile)cout<<"error"; 
	else{ 
		while(!feof(ffile)){ 
			ch=fgetc(ffile); 
			st+=ch; 
		}} 
	fclose(ffile); 
	return st; 
}
vector<POS> CReadMap::GetObject(string str,int number_object) 
{ 
	string *arr=new string[number_object*3+2]; 
	int i = 0; 
	stringstream ssin(str); 
	while (ssin.good() && i < number_object*3+2){ 
		ssin >> arr[i]; 
		++i; 
	} 

	vector<POS> list; 
	POS pos; 
	int index=i;
	POS pos_width;
	pos_width.width=atoi(arr[0].c_str());
	list.push_back(pos_width);
	POS pos_height;
	pos_height.height=atoi(arr[1].c_str());
	list.push_back(pos_height);
	for(int j=2;j<index;j=j+3) 
	{ 
		pos.type=atoi(arr[j].c_str());
		pos.x=atoi(arr[j+1].c_str());
		pos.y=atoi(arr[j+2].c_str());
		list.push_back(pos); 
	} 
	return list; 
} 